package com.hzdl.cinema.Service.impl;

import com.hzdl.cinema.Service.PlayViewService;
import com.hzdl.cinema.dao.PlayViewDao;
import com.hzdl.cinema.dao.impl.PlayViewDaoImpl;
import com.hzdl.cinema.domain.PageBean;
import com.hzdl.cinema.domain.Play;

import java.util.List;

public class PlayViewServiceImpl implements PlayViewService {
    PlayViewDao playViewDao = new PlayViewDaoImpl();

    @Override
    public PageBean<Play> searchMovie(String searchOne, int currentPage, int rows) {
        PageBean<Play> playPageBean = new PageBean<>();
//          当前页
        playPageBean.setCurrentPage(currentPage);
//          每页条数
        playPageBean.setRows(rows);
//          总条数
        Integer totalCount = playViewDao.searchTotalCount(searchOne);
        playPageBean.setTotalCount(totalCount);
//          总页数
        int totalPage = totalCount % rows == 0 ? totalCount / rows : totalCount / rows + 1;
        playPageBean.setTotalPage(totalPage);
//          每页的数据
        //（当前页数-1）*2
        int startRow = (currentPage - 1) * rows;
        List<Play> list = playViewDao.findSearch(searchOne, startRow, rows);
        playPageBean.setList(list);
//
        return playPageBean;
    }

    @Override
    public List<Play> findHot() {
        List<Play> list = playViewDao.findHot();
        return list;
    }

    //分页查询
    @Override
    public PageBean<Play> findMovie(int currentPage, int rows) {
        PageBean<Play> playPageBean = new PageBean<>();
//          当前页
        playPageBean.setCurrentPage(currentPage);
//          每页条数
        playPageBean.setRows(rows);
//          总条数
        int totalCount = playViewDao.findTotalCount();
        playPageBean.setTotalCount(totalCount);
//          总页数
        int totalPage = totalCount % rows == 0 ? totalCount / rows : totalCount / rows + 1;
        playPageBean.setTotalPage(totalPage);
       // 每页的数据
        //（当前页数-1）*2
        int startRow = (currentPage - 1) * rows;
        List<Play> list = playViewDao.findList(startRow, rows);
        playPageBean.setList(list);
        return playPageBean;

    }

    //影片详情
    @Override
    public Play filmDetails(String playName) {
       Play play= playViewDao.filmDetails(playName);
        return play;
    }
    @Override
    public List<Play> findAllPlay() {
        List<Play> allPlay=playViewDao.findMovie();
        return allPlay;
    }
}
